package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;

import java.nio.charset.Charset;

/**
 * Created by gjw on 2017/3/27.
 */

public class BindCamera extends BaseCommand {
    private byte[] ssid;
    private byte[] password;

    public BindCamera(String ssid, String password) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_BIND_CAMERA, 0);
        Charset utf8 = Charset.forName("utf8");
        this.ssid = ssid.getBytes(utf8);
        this.password = password.getBytes(utf8);
    }

    @Override
    protected short[] body() {
        int totalLen = 4 + ssid.length + password.length;
        short[] body = new short[totalLen];
        int off = 0;
        shortToUIntArray(body, off, (short) ssid.length);
        off += 2;
        byteArrayToUIntArray(body, off, ssid, 0);
        off += ssid.length;
        shortToUIntArray(body, off, (short) password.length);
        off += 2;
        byteArrayToUIntArray(body, off, password, 0);
        return body;
    }


    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        return new IResponse(ids(), ack.code);
    }
}
